§ Fox3.0常用插件清单
§ 前言
Fox3.0提供了丰富的原生API接口,以下内容可帮助您了解适用于您的应用的功能并开始使用相关 API。
§ API清单
| 名称 | 功能说明 |
|---|---|
| fox.device.callCamera | 相机组件管理 |
| fox.device.callVideo | 视频 |
| fox.device.callAudio | 音频组件管理 |
| fox.file.openImagePicker | 图片选择 |
| fox.file.openImageViewer | 图片浏览 |
| fox.device.callFace | 人脸识别 |
| fox.biometry.verify | 生物校验 |
| fox.timer | 定时器 |
| fox.native.getApkInfo | 获取APK信息 |
| fox.device.callIdr | 二代证读取 |
| fox.device.callSign | 签名 |
| fox.power | 电源设置 |
| fox.device.callFp | 指纹仪 |
| fox.keyboard | 密码键盘 |
| fox.file | 文件管理 |
| fox.http | 文件上传与下载 |
| fox.native | native接口 |
| fox.service | 消息推送 |
| fox.trace | 埋点记录 |
| fox.version | 版本设置 |
| fox.email | 邮箱管理 |
| fox.session | 共享session |
| fox.shareBus | 共享存储 |
§ 1. 基础
§ 1.1 日志打印
§ 1.1.1 debug
调用接口
console.debug(`debug,${this.msg}`)1
§ 1.1.2 info
调用接口
console.info(`info,${this.msg}`)1
§ 1.1.3 warn
调用接口
console.warn(`warn,${this.msg}`)1
§ 1.1.4 error
调用接口
let error = new Error('error') console.error(`error,${this.msg}`, error)1
2
§ 1.1.5 上传日志
调用接口
// 上传日志 async uploadLogFile() { let res = await fox.logger.uploadLogFile({ name: 'demo/file/upload', fileName: 'jc.txt', }) if(res.code == 0) { fox.layer.open('日志上传成功') }else{ fox.layer.open('日志上传失败') } }1
2
3
4
5
6
7
8
9
10
11
12
§ 1.2 定时器
§ 1.2.1 开启timer
调用接口
//开启timer startTimer(){ this.timerId = fox.timer.setTimer((code,message,data)=>{ fox.logger.info("执行任务.........."); },3000) },1
2
3
4
5
6
§ 1.2.2 关闭timer
调用接口
//关闭timer stopTimer() { if(this.timerId){ fox.timer.clearTimer(this.timerId) } }1
2
3
4
5
6
§ 1.2.3 关闭所有timer
调用接口
// 关闭所有timer clearAll() { if(this.timerId){ fox.timer.clearAll(this.timerId) } }1
2
3
4
5
6
§ 1.3 埋点记录
§ 1.3.1 记录
调用接口
data(){ return { type: 'trace', data: '我是消息,time:' + (new Date()), keyword1: '', keyword2: '', keyword3: '', keyword4: '', keyword5: '', } }, methods: { fox.trace.log(this.type, this.data, [this.keyword1, this.keyword2, this.keyword3, this.keyword4, this.keyword5]) }1
2
3
4
5
6
7
8
9
10
11
12
13
14参数说明
字段名 字段含义 类型 type 日志类型 String data 日志数据 String keywords 关键字 Array
§ 1.3.2 上传日志
调用接口
fox.trace.uploadLogFile()1
§ 2. 媒体
§ 2.1 相机
§ 2.1.1 相机
- 调用接口
// 参数
let params = {
maxSize: 100, // 图片大小,单位KB
quality: 70, // 图片质量 30~100
location: true, // 是开启定位,true为开启,false为关闭
watermark: true,
base64: true, // base64格式
mode: 'burstShot', // 连拍
}
// 调用前置相机
fox.device.callCamera('front', (code, message, data) => {
if (code == 0) {
if(fox.type(data) == 'string') {
data = JSON.parse(data)
}
if (data.base64Data) {
let imgData = 'data:image/png;base64,' + data.base64Data
// 设置图片
this.m_imgs = [imgData]
} else {
// 设置图片
this.m_imgs = [data.path]
}
} else {
fox.layer.open('拍照失败,message:' + message)
}
}, params)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
调用后置相机时,fox.device.callCamera()方法中的第一个参数传'back'
params参数说明
字段名 字段含义 类型 默认值 备注 maxWidth 图片最大的宽度 Number -1 maxHeight 图片最大的宽度 Number -1 minWidth 图片最小的宽度 Number -1 minHeight 图片最小的高度 Number -1 maxSize 图片最大尺寸,单位KB Number 2048 scale 图片缩放比例(如果设置width和height则忽略scale) Number 1 quality 图片质量 30~100 Number 100 format 文件格式 String jpeg orientation 拍照方向 String auto path 路径 String location 是否需绑定位置信息 Boolean false latitude 经度 Number -1 longitude 纬度 Number -1 addrStr 地址 String locationTimeout 定位超时时间 Number 3000 base64 图片返回格式 Boolean false watermark 是否加水印 Boolean false mode 拍照模式 String burstShot为连拍模式 maxNum 最大连拍数量 Number 500 pathList 连拍的文件列表 Array
§ 2.1.2 系统相机
调用接口
// 参数 let params = { maxSize: 500, // 单位KB } // 调用后置相机 fox.device.callSysCamera('back', (code, message, data) => { fox.layer.open('拍照完成 code:' + code) if (code == 0) { if(fox.type(data) == 'string') { data = JSON.parse(data) } if (data.base64Data) { let imgData = 'data:image/png;base64,' + data.base64Data // 设置图片 this.m_imgs = [imgData] } else { // 设置图片 this.m_imgs = [data.path] } } else { fox.layer.open('拍照失败,message:' + message) } }, params)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23params参数说明
字段名 字段含义 类型 默认值 maxSize 图片最大尺寸,单位KB Number 2048 format 文件格式 String jpg path 文件路径 String null location 是否需绑定位置信息 Boolean false latitude 经度 Number -1 longitude 纬度 Number -1 addrStr 地址 String locationTimeout 定位超时时间 Number 300 base64 获取图片返回格式 Boolean false watermark 是否加水印 Boolean false
§ 2.2 视频
调用接口
//参数列表 let params = { quality: 0, maxDuration: -1, path:"localExtCache://myData/1.mp4" }; //开始录像 fox.device.callVideo("startRecorder", (code, message, data) => { if (code == 0) { data = JSON.parse(data); //保存路径 vm.path = data.path; fox.logger.info("录像成功,path:" + vm.path); fox.layer.open("录像成功"); } else { fox.layer.open("录像失败"); } }, params);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18params参数说明
字段名 字段含义 类型 默认值 quality 录像 0:低质量, 1:高质量 Number maxDuration 最长录制时间 Number -1 maxFileSize 最大文件大小 Number -1 path 路径 String null front 是否使用前置摄像头 Boolean false
§ 2.3 录音
§ 2.3.1 开始录音
调用接口
//开始录音 let params = { maxDuration: 60000 }; fox.device.callAudio("startRecorder",(code, message, data)=>{ if (code == 0) { data = JSON.parse(data); //保存路径 this.path = data.path; fox.logger.info("录音成功,path:"+vm.path); fox.layer.open("录音成功"); }else{ fox.layer.open("录音失败"); } this.recorderDisabled=false; },params);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16params参数说明
字段名 字段含义 类型 默认值 path 文件路径 String null maxDuration 最长录制时间 Number -1 maxFileSize 最大文件大小 Number -1
§ 2.3.2 停止录音
调用接口
//停止录音 fox.device.callAudio("stopRecorder");1
2
§ 2.3.3 重新录音
调用接口
//重新录音 fox.device.callAudio("reRecorder");1
2
§ 2.3.4 播放录音
调用接口
var params = { path: '' }; //调用播放 fox.device.callAudio("startPlay", function (code, message, data) { fox.layer.open("播放完成"); }, params);1
2
3
4
5
6
7params 参数说明
字段名 字段含义 类型 默认值 path 文件路径 String null
§ 2.4 图片
§ 2.4.1 图片选择
调用接口
fox.file.openImagePicker((code,message,data)=>{ if(fox.type(data) == "string"){ data = JSON.parse(data); } this.items=data; })1
2
3
4
5
6
§ 2.4.2 图片浏览
调用接口
let params = { items: [], index: 0, canDelete: false } fox.file.openImageViewer(params)1
2
3
4
5
6params参数说明
字段名 字段含义 类型 默认值 items 获取路径 Array index 获取索引 Number 0 canDelete 是否能删除 Boolean false
§ 3. 生物认证
§ 3.1 人脸识别
说明:根据市场上封装的不同,其调用的参数不同。
调用接口
//人脸识别 fox.device.callFace("read",(code, message, data)=>{ if (code == 0) { fox.layer.open("人脸识别调用成功:" + JSON.stringify(data)); } else { fox.layer.open("人脸识别调用失败:" + message); } },{cover:false})1
2
3
4
5
6
7
8
9
§ 3.2 生物识别
说明:生物识别包括人脸识别、虹膜识别、指纹识别等等。
调用接口
//生物认证 fox.biometry.verify((code,message,data)=>{ if(code != 0) { fox.layer.open("生物验证不通过:"+message); } else { if(fox.type(data) == "object"){ data = JSON.stringify(data) } fox.layer.open("生物验证通过: "+data); } },{message:"请进行身份认证",cover:false}); //是否支持生物检测 fox.biometry.isAvailable((code,message,data)=>{ if(code != 0){ fox.layer.open("生物识别不可用,message:"+message+", data:"+data); }else { if(fox.type(data)=="string"){ data = JSON.parse(data) } if(data.type == "FaceID"){ this.text="人脸识别" }else if(data.type == "TouchID"){ this.text="指纹识别" }else{ this.text="无识别" } fox.layer.open("生物识别可用: "+JSON.stringify(data)); } })1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
§ 4. APK信息
§ 4.1 获取APK信息
调用接口
//获取APK信息 fox.native.getApkInfo("",(code, message, data)=>{ if(code == 0){ fox.layer.open(JSON.stringify(data)) }else{ fox.layer.open(message) } })1
2
3
4
5
6
7
8
§ 4.2 APK完整校验
调用接口
//APK完整校验 fox.native.call("countApkMD5", "count", (code, message ,data)=>{ if(code == 0){ this.targetMD5 = data; if(this.targetMD5 == this.sourceMD5){ fox.layer.open("APK完整性校验通过"); }else{ fox.layer.open("APK完整性校验不通过"); } }else{ fox.layer.open("获取APK MD5信息失败"); } })1
2
3
4
5
6
7
8
9
10
11
12
13
§ 5. 二代证读取
调用接口
//二代证读取 fox.device.callIdr("read",function (code, message, data) { if (code == 0) { fox.layer.open("二代证调用成功:" + data); } else { fox.layer.open("二代证调用失败:" + message); } })1
2
3
4
5
6
7
8
§ 6. 签名
调用接口
//签名测试 fox.device.callSign((code, message, data)=> { this.img=""; if(code==0){ this.img=data+"?time="+(new Date()).getTime(); fox.layer.open("调用签名成功:"+this.img); }else if(code==1){ fox.layer.open("调用签名取消"); }else{ fox.layer.open("调用签名错误"); } })1
2
3
4
5
6
7
8
9
10
11
12
§ 7. 电源设置
§ 7.1 是否在白名单
调用接口
//是否在白名单中 fox.power.isInWhiteList((code, message, data)=>{ if(data == true){ fox.layer.open("应用在白名单中"); }else{ fox.layer.open("应用不在白名单中"); } });1
2
3
4
5
6
7
8
9
§ 7.2 加入白名单
调用接口
//加入白名单 fox.power.addWhiteList((code, message, data)=>{ fox.layer.open("加入白名单完成"); });1
2
3
4
§ 8. 指纹仪
调用接口
//指纹仪 fox.device.callFp("collect",function (code, message, data) { if (code == 0) { fox.layer.open("指纹仪调用成功:" + data); } else { fox.layer.open("指纹仪调用失败:" + message); } })1
2
3
4
5
6
7
8
§ 9. 密码键盘
§ 9.1 RSA加密
调用接口
let id = 'rsa', isNumber = false, confuse = 1, maxLength = 10, showEditText = true, watchOutside = false, buttonPress = false, inputReg = '' let reg = '^(?![^a-zA-Z]+$)(?!\\D+$).{6,16}$' let params = [id, isNumber, confuse, maxLength, showEditText, watchOutside, buttonPress, reg, inputReg] fox.keyboard.openRSAKeyboard(params,(code, message, data) => { if (code == 0) { if(fox.type(data)==="string"){ data=JSON.parse(data); } let payload=data.payload; this.pwdrsa = payload.text; this.cipherText = payload.cipherText; } else { fox.layer.open(message); } });1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16params参数说明见9.7
§ 9.2 MD5加密
调用接口
let id = 'md5', isNumber = false, confuse = 1, maxLength = 11, showEditText = true, watchOutside = false, buttonPress = false, inputReg = '' let reg = '^(13[0-9]|14[579]|15[0-3,5-9]|17[0135678]|18[0-9])\\d{8}$' let params = [id, isNumber, confuse, maxLength, showEditText, watchOutside, buttonPress, reg, inputReg] fox.keyboard.openMD5Keyboard(params,(code, message, data)=>{ if (code == 0) { if(fox.type(data)==="string"){ data=JSON.parse(data); } let payload=data.payload; this.pwdmd5 = payload.text; this.cipherText = payload.cipherText; } else { fox.layer.open(message); } });1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16params参数说明见9.7
§ 9.3 AES加密
调用接口
// ase加密 let id = 'ase', isNumber = false, confuse = 1, maxLength = 10, showEditText = true, watchOutside = true, buttonPress = true, inputReg = '' let reg = '^(?![^a-zA-Z]+$)(?!\\D+$).{6,16}$' let params = [id, isNumber, confuse, maxLength, showEditText, watchOutside, buttonPress, reg, inputReg] fox.keyboard.openAESKeyboard(params,(code, message, data)=>{ if (code == 0) { if(fox.type(data)==="string"){ data=JSON.parse(data); } let payload=data.payload; this.pwdaes = payload.text; this.cipherText = payload.cipherText; } else { fox.layer.open(message); } });1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17params参数说明见9.7
§ 9.4 SM2加密
调用接口
// SM2加密 let id = 'sm2', isNumber = false, confuse = 1, maxLength = 10, showEditText = true, watchOutside = false, buttonPress = false, inputReg = '' let reg = '^(?![^a-zA-Z]+$)(?!\\D+$).{6,16}$' let params = [id, isNumber, confuse, maxLength, showEditText, watchOutside, buttonPress, reg, inputReg] fox.keyboard.openSM2Keyboard(params,(code, message, data)=>{ if (code == 0) { if(fox.type(data)==="string"){ data=JSON.parse(data); } let payload=data.payload; this.pwdsm2 = payload.text; this.cipherText = payload.cipherText; } else { fox.layer.open(message); } });1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17params参数说明见9.7
§ 9.5 SM3加密
调用接口
// SM3加密 let id = 'sm3', isNumber = false, confuse = 1, maxLength = 10, showEditText = true, watchOutside = false, buttonPress = false, inputReg = '' let reg = '^(?![^a-zA-Z]+$)(?!\\D+$).{6,16}$' let params = [id, isNumber, confuse, maxLength, showEditText, watchOutside, buttonPress, reg, inputReg] fox.keyboard.openSM3Keyboard(params,(code, message, data)=>{ if (code == 0) { if(fox.type(data)==="string"){ data=JSON.parse(data); } let payload=data.payload; this.pwdsm3 = payload.text; this.cipherText = payload.cipherText; } else { fox.layer.open(message); } });1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17params参数说明见9.7
§ 9.6 SM4加密
调用接口
// SM4加密 let id = 'sm4', isNumber = false, confuse = 1, maxLength = 10, showEditText = true, watchOutside = true, buttonPress = false, inputReg = '' let reg = '^(?![^a-zA-Z]+$)(?!\\D+$).{6,16}$' let params = [id, isNumber, confuse, maxLength, showEditText, watchOutside, buttonPress, reg, inputReg] fox.keyboard.openSM4Keyboard(params,(code, message, data)=>{ if (code == 0) { if(fox.type(data)==="string"){ data=JSON.parse(data); } let payload=data.payload; this.pwdsm4 = payload.text; this.cipherText = payload.cipherText; } else { fox.layer.open(message); } });1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17params参数说明见9.7
§ 9.7 清空密码键盘
调用接口
// 清空密码键盘 let id = 'sm4' fox.keyboard.clearKeyboard(id);1
2
3params参数说明
字段名 字段含义 类型 默认值 id id名称 String isNumber 是否数字键盘 Boolean false confuse 是否混乱排序 Number 1 maxLength 最大长度 Number 100 showEditText 是否显示edit text Boolean false watchOutside 空白区域关闭键盘 Boolean true buttonPress 是否显示按压 Boolean true reg 匹配正则表达式 String inputReg 输入正则表达式 String
§ 10. 文件访问
§ 10.1 来源文件(拍照)
调用接口
let params = { maxWidth: 1000, // 图片最大宽度 maxHeight: 1000, // 图片最小宽度 quality: 70, // 图片质量 30~100 mode: 'burstShot', // 连拍 path: this.m_dir, } try{ // 调用后置相机 let res = await fox.device.callCamera('back', params) fox.layer.open('拍照完成 code:' + code) this.sourcePaths = [] if (res.code == 0) { let array if(typeof res.data == 'string') { array = JSON.parse(res.data) }else{ array = res.data } for (let i = 0; i < array.length; i++) { this.sourcePaths.push(array[i].path || 'data:image/png;base64,' + array[i].base64Data) } } else { fox.layer.open('拍照失败,message:' + message) } }catch(ex) { fox.layer.open('拍照失败,message:' + ex.message) }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29params参数说明
字段名 字段含义 类型 默认值 mode 获取拍照模式 String maxNum 最大连拍数量 Number 500 maxWidth 图片最大的宽度 Number -1 maxHeight 图片最大的宽度 Number -1 minWidth 图片最小的宽度 Number -1 minHeight 图片最小的高度 Number -1 maxSize 图片最大尺寸,单位KB Number 2048 scale 片缩放比例(如果设置width和height则忽略scale) Number 1 quality 图片质量 30~100 Number 100 format 文件格式 String jpeg orientation 拍照方向 String auto path 路径 String pathList 连拍的文件列表 Array location 是否需绑定位置信息 Boolean false latitude 经度 Number -1 longitude 纬度 Number -1 addrStr 地址 String locationTimeout 定位超时时间 Number 3000 base64 图片返回格式 Boolean false watermark 是否加水印 Boolean false
§ 10.2 来源文件(选择)
调用接口
// 选择来源文件 try{ let res = await fox.file.choose('', { openFile: true, openDirectory: false }) if (res.code == 0) { console.info(res.data) let list if(typeof res.data == 'string') { list = JSON.parse(res.data) }else{ list = res.data } this.sourcePaths = list console.info(list.length) fox.layer.open(JSON.stringify(list)) } }catch(ex) { console.error(ex.message, ex) fox.layer.open(ex.message) }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
§ 10.3 目标目录(选择)
调用接口
// 选择目标文件 try{ let res = await fox.file.choose('', { openFile: false, openDirectory: true }) if (res.code == 0) { console.info(res.data) let list if(typeof res.data == 'string') { list = JSON.parse(res.data) }else{ list = res.data } this.targetDir = list[0] console.info(list.length) fox.layer.open(JSON.stringify(list)) } }catch(ex) { console.error(ex.message, ex) fox.layer.open(ex.message) }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
§ 10.4 打开路径下文件
调用接口
// 打开路径下文件 async openFile() { let sourcePaths = 'workSpace\text.txt' let res = await fox.file.open(sourcePaths) if (res.code != 0) { fox.layer.open(res.message) } }1
2
3
4
5
6
7
8参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.5 获取绝对路径
调用接口
// 获取绝对路径 let sourcePaths = 'workSpace\text.txt' let path = fox.file.getAbsolutePath(sourcePaths || '') fox.layer.open(path)1
2
3
4参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.6 路径是否存在
调用接口
// 路径是否存在 let sourcePaths = 'workSpace\text.txt' let exists = fox.file.exists(sourcePaths) fox.layer.open(`${exists}`)1
2
3
4参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.7 路径是否为文件夹
调用接口
// 路径是否为文件夹 let targetDir = 'localExtCache://myData/example' let isDirectory = fox.file.isDirectory(targetDir) fox.layer.open(`${isDirectory}`)1
2
3
4参数说明
字段名 字段含义 类型 targetDir 目标文件夹路径 String
§ 10.8 路径是否为文件
调用接口
// 路径是否为文件 let sourcePaths = 'workSpace\text.txt' let isFile = fox.file.isFile(sourcePaths) fox.layer.open(`${isFile}`)1
2
3
4参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.9 删除路径下文件/文件夹
调用接口
// 删除路径下文件/文件夹 let sourcePaths = 'workSpace\text.txt' fox.file.delete(sourcePaths, (code, message, data) => { if (code == 0) { fox.layer.open('删除成功') } else { fox.layer.open('删除失败:' + message) } })1
2
3
4
5
6
7
8
9参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.10 拷贝路径下文件/文件夹
调用接口
// 拷贝路径下文件/文件夹 let sourcePaths = 'workSpace\text.txt' let targetDir = 'localExtCache://myData/example' fox.file.copy(sourcePaths, targetDir, (code, message, data) => { if (code == 0) { fox.layer.open('拷贝成功') } else { fox.layer.open('拷贝失败:' + message) } })1
2
3
4
5
6
7
8
9
10参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String targetDir 目标文件夹路径 String
§ 10.11 移动路径下文件/文件夹
调用接口
// 移动路径下文件/文件夹 let sourcePaths = 'workSpace\text.txt' let targetDir = 'localExtCache://myData/example' fox.file.move(sourcePaths, targetDir, (code, message, data) => { if (code == 0) { fox.layer.open('移动成功') } else { fox.layer.open('移动失败:' + message) } })1
2
3
4
5
6
7
8
9
10参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String targetDir 目标文件夹路径 String
§ 10.12 列出路径下文件列表
调用接口
// 列出路径下文件列表 let targetDir = 'localExtCache://myData/example' fox.file.list(targetDir, (code, message, data) => { if(typeof data == 'string') { data = JSON.parse(data) } fox.layer.open('文件列表:' + JSON.stringify(data)) })1
2
3
4
5
6
7
8参数说明
字段名 字段含义 类型 targetDir 目标文件夹路径 String
§ 10.13 获取路径下文件(以字符串文字展示)
调用接口
// 获取路径下文件(以字符串文字展示) let sourcePaths = 'workSpace\text.txt' let res = await fox.file.getContentAsString(sourcePaths) if(res.code == 0) { fox.layer.open(res.data) }else{ fox.layer.open('获取文件内容失败(string)') }1
2
3
4
5
6
7
8参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.14 获取路径下文件(以base64字符串展示)
调用接口
// 获取路径下文件(以base64字符串展示) let sourcePaths = 'workSpace\text.txt' let res = await fox.file.getContentAsBase64(sourcePaths) if(res.code == 0) { fox.layer.open(res.data) }else{ fox.layer.open('获取文件内容失败(base64)') }1
2
3
4
5
6
7
8参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.15 获取路径下文件/文件夹长度
调用接口
let sourcePaths = 'workSpace\text.txt' let length = fox.file.length(sourcePaths) fox.layer.open(`${length}`)1
2
3参数说明
字段名 字段含义 类型 sourcePaths 源文件路径 Array/String
§ 10.16 选择并拷贝文件
调用接口
// 选择文件并copy fox.file.choose('', (code, message, data) => { if (code == 0) { let list if(typeof data == 'string') { list = JSON.parse(data) } console.info(list.length) // 目标保持目录 let targetDirectory = this.targetDir || 'localExtCache://copy_tmp' for (let i = 0; i < list.length; i++) { // 获取目标文件名 let fileName let index = list[i].lastIndexOf('/') if (index != -1) { fileName = list[i].substring(index) } else { fileName = '/unknown' } console.info(list[i]) // 拷贝文件 fox.file.copy(list[i], targetDirectory + fileName) } } })1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
§ 10.14 以base64内容设置文件(文件内容用base64编码)
调用接口
// 获取路径下文件(以base64字符串展示) let path = 'workSpace\text.txt' let data = '' let res = await fox.file.setContentAsBase64(path,data)1
2
3
4
5参数说明
字段名 字段含义 类型 path 文件路径 String data base64格式数据 String
§ 11.文件上传与下载(native)
§ 11.1 上传(异步)
调用接口
let remoteSavePath = 'upload/myData' let remoteFileName = 'jc.jpeg' let uploadFilePath = this.m_paths[0] let params = { async: true, } fox.http.upload(remoteSavePath, remoteFileName,uploadFilePath, params, (code, message, data) => { if(code == 0) { fox.layer.open('上传成功') }else{ fox.layer.open('上传失败:' + message) } })1
2
3
4
5
6
7
8
9
10
11
12
13
14params参数说明
字段名 字段含义 类型 默认值 async 是否为异步 Boolean timeout 超时时间 Number -1 cover 是否需要打开cover Boolean false
§ 11.2 下载(异步)
调用接口
let remotePath = 'upload/myData/jc.jpeg' let savePath = 'localExtCache://myData/jc.jpeg' let params = { async: true, } fox.http.download(remotePath, savePath,params, (code, message, data) => { if(code == 0) { let s = fox.file.getAbsolutePath(savePath) this.m_paths = [s] fox.layer.open(`下载成功,path:${s}`) }else{ this.m_paths = [] fox.layer.open('下载失败:' + message) } })1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16params参数说明
字段名 字段含义 类型 默认值 async 是否为异步 Boolean timeout 获取超时时间 Number -1 fileService 获取文件服务名 String null cover 是否需要打开cover Boolean false thumbnail 是否需要打开缩略图 Boolean false
§ 11.3 直接上传(异步)
调用接口
let servicePath = 'demo/file/upload' let uploadFilePath = this.m_paths[0] // 参数 let params = { async: true, } // 上传给服务的数据 let data = { path: 'upload/myData/jc-2.jpeg', key1: '1', key2: '2', user: { name: '江成', id: '007', }, } let headers = {} fox.http.directUpload({ name: servicePath, uploadFilePath: uploadFilePath, params: params, headers: headers, data: data, callback: (code, message, resData) => { if(code == 0) { fox.layer.open('上传成功') }else{ fox.layer.open('上传失败:' + message) } }, })1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32params参数说明
字段名 字段含义 类型 默认值 async 是否为异步 Boolean timeout 获取超时时间 Number -1 cover 是否需要打开cover Boolean false raw 是否第三方 Boolean false
§ 11.4 直接下载(异步)
调用接口
let servicePath = 'demo/file/download' let savePath = 'localExtCache://myData/jc-2.jpeg' // 参数 let params = { async: true, } // 上传给服务的数据 let data = { path: 'upload/myData/jc-2.jpeg', key1: '1', key2: '2', } let headers = {} fox.http.directDownload({ name: servicePath, savePath: savePath, params: params, headers: headers, data: data, callback: (code, message, resData) => { if(code == 0) { let s = fox.file.getAbsolutePath(savePath) this.m_paths = [s] }else{ fox.layer.open('下载失败:' + message) } }, })1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29params参数说明
字段名 字段含义 类型 默认值 async 是否为异步 Boolean timeout 获取超时时间 Number -1 cover 是否需要打开cover Boolean false raw 是否第三方 Boolean false method 获取请求方法 String POST
§ 11.5 断点上传(异步)
调用接口
let remoteSavePath = 'upload/myData' let remoteFileName = 'jc-3.jpeg' let uploadFilePath = this.m_paths[0] let pageSize = 10 let param = { async: true, } fox.http.breakpointUpload(remoteSavePath, remoteFileName, uploadFilePath,pageSize, param, (code, message, resData) => { if(code == 0) { fox.layer.open('上传成功') }else if(code == 3) { console.info('rate=' + resData) } else{ fox.layer.open('上传失败:' + message) } })1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17param参数说明
字段名 字段含义 类型 默认值 async 是否为异步 Boolean timeout 获取超时时间 Number -1 cover 是否需要打开cover Boolean false
§ 11.6 断点下载(异步)
调用接口
let remotePath = 'upload/myData/jc-3.jpeg' let savePath = 'localExtCache://myData/jc-3.jpeg' let pageSize = 1 let params = { async: true, cover: true, } fox.http.breakpointDownload(remotePath, savePath,pageSize, params, (code, message, resData) => { if(code == 0) { let s = fox.file.getAbsolutePath(savePath) this.m_paths = [s] }else if(code == 3) { console.info('rate=' + resData) }else{ fox.layer.open('下载失败:' + message) } })1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18param参数说明
字段名 字段含义 类型 默认值 async 是否为异步 Boolean timeout 获取超时 Number -1 fileService 文件服务名 String null cover 是否需要打开cover Boolean false
§ 11.7 静默上传
调用接口
let queue = fox.http.silentUploadQueue('upload', -1, 3) queue.add(this.m_paths) queue.wait((flag) => { fox.layer.open('文件上传结果flag:' + flag) }, '文件上传中')1
2
3
4
5
§ 12. native接口
§ 12.1 获取位置信息
调用接口
fox.native.getLocation((code, message, data) => { if(code == 0) { fox.layer.open('获取位置信息成功:' + data) }else{ fox.layer.open('获取位置信息失败:' + message) } }, false)1
2
3
4
5
6
7
§ 12.2 检查WIFI是否开启
调用接口
fox.native.checkWifi((code, message, data) => { if(code == 0) { fox.layer.open('检查WIFI状态成功:' + data) }else{ fox.layer.open('检查WIFI状态失败:' + message) } })1
2
3
4
5
6
7
§ 12.3 获取IP地址
调用接口
fox.native.getLocalIP((code, message, data) => { if(code == 0) { fox.layer.open('获取IP成功:' + data) }else{ fox.layer.open('获取IP失败:' + message) } })1
2
3
4
5
6
7
§ 12.4 获取MAC地址
调用接口
fox.native.getLocalMac((code, message, data) => { if(code == 0) { fox.layer.open('获取Mac成功:' + data) }else{ fox.layer.open('获取Mac失败:' + message) } })1
2
3
4
5
6
7
§ 12.5 重启与关闭APP
调用接口
// 重启APP fox.native.restart() // 关闭APP fox.native.shutdown()1
2
3
4
5
§ 12.6 app version
§ 12.6.1 app version name
调用接口
//APP Version Name async getAppVersionName() { let res = await fox.native.getAppVersionName() fox.layer.open(`app version name:${res.data}`) }1
2
3
4
5
§ 12.6.2 app version code
调用接口
//APP Version Code async getAppVersionCode() { let res = await fox.native.getAppVersionCode() fox.layer.open(`app version code:${res.data}`) }1
2
3
4
5
§ 12.7 获取电话号码
调用接口
fox.native.getNumber((code, message, data) => { if(code == 0) { fox.layer.open('获取number成功:' + data) }else{ fox.layer.open('获取number失败:' + message) } })1
2
3
4
5
6
7
§ 12.8 推送
调用接口
let param = { contentTitle: 'Fox消息', contentText: '测试测试' + new Date(), subText: '', ticker: '', } fox.native.notify(param, (code, message, data) => { if(code == 0) { fox.layer.open('通知成功') }else{ fox.layer.open('通知失败:' + message) } })1
2
3
4
5
6
7
8
9
10
11
12
13
14param参数说明
字段名 字段含义 类型 默认值 contentTitle 通知标题 String Fox contentText 通知内容 String subText 通知内容详情 String ticker 消息提示 String 您收到新的消息
§ 12.9 打电话与挂电话
§ 12.9.1 打电话
调用接口
let param = { number: '15632784930', } fox.native.callPhone(param, (code, message, data) => { if (code == 0) { fox.logger.debug('打电话成功') fox.layer.open('message' + message + ',data:' + JSON.stringify(data)) } else { fox.layer.open('打电话失败:' + message) } })1
2
3
4
5
6
7
8
9
10
11
12param 参数说明
字段名 字段含义 类型 默认值 number 电话号码 String null
§ 12.9.2 挂电话
调用接口
fox.native.endPhone({}, (code, message, data) => { if (code == 0) { $.logger.debug('挂电话成功') } else { fox.layer.open('打电话失败:' + message) } })1
2
3
4
5
6
7
§ 15. 消息推送
§ 15.1 注册
调用接口
// 注册 fox.service.registerMessageService('demo', (name, data) => { // 处理information消息 if (data.msgType == '#info') { // 记录地址 let address = data.content console.info('1.建立连接,返回标识地址:' + address) fox.service.request({ name: 'demo/demo/webSocket', data: { address: address }, callback: (code, message, content) => { console.info('2.标识地址记录成功:' + JSON.stringify(content)) fox.layer.open('标识地址记录成功:' + JSON.stringify(content)) }, }) }else { fox.layer.open('web socket通知:' + data.content) } }, 300)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
§ 15.2 注销
调用接口
// 注销 fox.service.unRegisterMessageService('demo')1
2
§ 16. 版本设置
§ 16.1 设置灰度
调用接口
// 设置灰度 let scale = '' fox.version.setVersionScale(scale);1
2
3
§ 16.2 获取灰度
调用接口
// 获取灰度 let data = fox.version.getVersionScale(); if(fox.type(data) == "string"){ data = JSON.parse(data) } if(data.code == 0){ fox.layer.open(data.data) }else{ fox.layer.open(data.message) }1
2
3
4
5
6
7
8
9
10
§ 16.3 获取版本号
调用接口
// 获取版本 fox.version.getVersion((code, message, data)=>{ if(code == 0){ if(fox.type(data) == "object"){ data = JSON.stringify(data) } fox.layer.open(data) }else{ fox.layer.open(message) } });1
2
3
4
5
6
7
8
9
10
11
§ 17. 唯一 ID
调用接口
// 获取唯一ID fox.native.getUniqueID((code, message, data) => { this.uniqueId = data })1
2
3
4
§ 18. 邮箱
§ 18.1 打开邮箱
调用接口
let args = { user: 'hello', password: '123456', } fox.email.open(args, (code, message, data) => { })1
2
3
4
5
6args参数说明
字段名 字段含义 类型 user 用户名 String password 密码 String
§ 18.2 关闭邮箱
调用接口
// 关闭邮箱 fox.email.close((code, message, data) => { })1
2
3
§ 19. 共享session
§ 19.1 设置共享session名称
调用接口
fox.session.setShareNames(['fox_app','fox_ext'])1
§ 19. 2 获取共享session名称
调用接口
let s = fox.session.getShareNames() fox.layer.open(JSON.stringify(s));1
2
§ 20. 共享存储
§ 20.1 设置共享数据
调用接口
fox.shareBus.put(key, val)1参数说明
字段名 字段含义 类型 key 共享数据中指定的key String val 需要共享的内容 Any
§ 20.2 获取共享数据
调用接口
let data = fox.shareBus.get(key) fox.layer.open(`share value:${data}`)1
2
§ 20.3 删除共享数据
调用接口
let data = fox.shareBus.remove(key) fox.layer.open(`share data:${data}`)1
2
← 常用工具类